﻿using System.Collections.Generic;
using System.Dynamic;

namespace DbExtendedProvider
{
	public class DynamicDictionary : DynamicObject
	{
		private readonly Dictionary<string, string> _dictionary = new Dictionary<string, string>();

		public override bool TryGetMember(GetMemberBinder binder,
		                                  out object result)
		{
			string data;
			if (!_dictionary.TryGetValue(binder.Name, out data))
			{
				result = null;
				return false;
			}
			result = data;
			return true;
		}

		public override bool TrySetMember(SetMemberBinder binder, object value)
		{
			try
			{
				if (value == null)
				{
					_dictionary[binder.Name] = null;
				}
				else
				{
					_dictionary[binder.Name] = value.ToString();
				}
			}
			catch 
			{
				return false;
			}
			return true;
		}

		public DynamicDictionary()
		{
		}

		public DynamicDictionary(string serialized)
		{

		}

	}
}

